
import 'dart:ffi';

import 'package:json_annotation/json_annotation.dart';

import '../../../util/DateUtil.dart';
import '../base/Req.dart';
import 'Message.dart';

part 'PullData.g.dart';

@JsonSerializable()
class DepartmentInfoListReq extends Req {

	String? startOrgCode;
	int? pageSize;
	DateTime? startDate;
	bool isLatestChange = true;

	DepartmentInfoListReq();

	Map<String, dynamic> toJson() => _$DepartmentInfoListReqToJson(this);
}

@JsonSerializable()
class DepartmentInfoListItem {
	List<DepartmentInfoItem> departmentInfoItemList;

	DepartmentInfoListItem(this.departmentInfoItemList);

	factory DepartmentInfoListItem.fromJson(Map<String, dynamic> map) =>_$DepartmentInfoListItemFromJson(map);

	Map<String, dynamic> toJson() => _$DepartmentInfoListItemToJson(this);
}

@JsonSerializable()
class DepartmentInfoItem {
	String orgCode;
	String departmentName;
	String? parentCode = null;
	String? desc;
	String? managerUserId;
	Set<String>? otherManagerUserIdList;
	EnableType? status;

	DepartmentInfoItem(this.orgCode, this.departmentName);

	factory DepartmentInfoItem.fromJson(Map<String, dynamic> map) =>_$DepartmentInfoItemFromJson(map);

	Map<String, dynamic> toJson() => _$DepartmentInfoItemToJson(this);
}

@JsonSerializable()
class UserInfoListReq extends Req {
	String? startUserId;
	int pageSize = 1000;
	DateTime? startDate;
	bool isLatestChange = false;

	UserInfoListReq();

	Map<String, dynamic> toJson() => _$UserInfoListReqToJson(this);
}

@JsonSerializable()
class UserInfoListItem {
	List<UserInfoItem> userInfoItemList;

	UserInfoListItem(this.userInfoItemList);

	factory UserInfoListItem.fromJson(Map<String, dynamic> map) =>_$UserInfoListItemFromJson(map);

	Map<String, dynamic> toJson() => _$UserInfoListItemToJson(this);
}

@JsonSerializable()
class UserInfoItem {
	String userId;
	String userName;
	String? mobile;
	String? headImg;
	String? motto;  // 座右铭
	SexEnum sex;   // 性别
	EnableType? status;
	String? departmentCode = null;  //　部门id
	Set<String>? otherDepartmentCodeList;  // 兼任部门
	String? firstLetter;

	UserInfoItem(this.userId, this.userName, this.mobile, this.sex);

	factory UserInfoItem.fromJson(Map<String, dynamic> map) =>_$UserInfoItemFromJson(map);

	Map<String, dynamic> toJson() => _$UserInfoItemToJson(this);
}

enum SexEnum {
	male(1, "男性"),
	female(2, "女性"),
	;

	final int value;
	final String desc;

	const SexEnum(this.value, this.desc);

	static SexEnum ofValue(int? value) {
		SexEnum? result = SexEnum.values.firstWhere((e) => e.value == value);
		return result;
	}
}

enum GroupType {
	chat,
}

@JsonSerializable()
class GroupInfoListReq extends Req {

	GroupType groupType;
	DateTime? startDate;
	String? startServerId;
	int? pageSize = 300;
	bool isLatestChange = true;

	GroupInfoListReq(this.groupType);

	Map<String, dynamic> toJson() => _$GroupInfoListReqToJson(this);
}

@JsonSerializable()
class GroupInfoListItem {

	List<GroupInfoItem> groupInfoItemList;

	GroupInfoListItem(this.groupInfoItemList);

	factory GroupInfoListItem.fromJson(Map<String, dynamic> map) =>_$GroupInfoListItemFromJson(map);

	Map<String, dynamic> toJson() => _$GroupInfoListItemToJson(this);
}

@JsonSerializable()
class GroupInfoItem {
	String? sessionId;
	String groupId;
	String? groupName;
	String? ownerId;                  // 群主
	String? groupDesc;                // 群公告
	Set<GroupUser>? groupUserSet;      // 添加用户
	Map<String, String>? groupInfo;   // 群属性
	GroupStatus? status;
	String? firstLetter;

	GroupInfoItem(this.groupId, this.groupName, this.groupUserSet);

	factory GroupInfoItem.fromJson(Map<String, dynamic> map) =>_$GroupInfoItemFromJson(map);

	Map<String, dynamic> toJson() => _$GroupInfoItemToJson(this);
}

@JsonSerializable()
class GroupUser {
	String userId;
	String? userName;
	GroupUserStatus? status;
	bool isShowName;
	bool isWaking;
	bool isTop;
	bool isDisturb;

	GroupUser(this.userId) :
			this.isShowName = true,
			this.isWaking = false,
			this.isTop = false,
			this.isDisturb = true
			;

	factory GroupUser.fromJson(Map<String, dynamic> map) =>_$GroupUserFromJson(map);

	Map<String, dynamic> toJson() => _$GroupUserToJson(this);
}

@JsonSerializable()
class SessionPullReq extends Req {
	int pageSize;             // 获取个数
	DateTime? startDate;
	SessionType? sessionType;
	String? startServerId;

	SessionPullReq(this.pageSize);

	Map<String, dynamic> toJson() => _$SessionPullReqToJson(this);
}

@JsonSerializable()
class SessionItemList {
	List<SessionItem> sessionItemList;

	SessionItemList(this.sessionItemList);

	factory SessionItemList.fromJson(Map<String, dynamic> map) =>_$SessionItemListFromJson(map);

	Map<String, dynamic> toJson() => _$SessionItemListToJson(this);
}

@JsonSerializable()
class SessionItem {
	String? groupId;            // 群组
	String? userId;             // 单聊组
	String? serverId;
	int hotMessageTotal;
	String latelyMessage;
	bool isTop = false;        // 是否置顶
	bool isDisturb = false;    // 是否免打扰
	bool isTop2 = false;        // 是否置顶
	bool isDisturb2 = false;    // 是否免打扰
	SessionType sessionType;
	String? name;
	SessionStatus status;
	DateTime updateTime;

	SessionItem() :
		this.hotMessageTotal = 0,
		this.latelyMessage = '',
		this.isTop = false,
		this.isDisturb = false,
		this.isTop2 = false,
		this.isDisturb2 = false,
		this.sessionType = SessionType.chat,
	  this.status = SessionStatus.enable,
		this.updateTime = DateTime.now()
	;

	factory SessionItem.fromJson(Map<String, dynamic> map) =>_$SessionItemFromJson(map);

	Map<String, dynamic> toJson() => _$SessionItemToJson(this);
}

@JsonSerializable()
class MessagePullBySessionIdsReq extends Req {
	String? startServerMessageId;
	int? pageSize;
	Set<String> sessionIds;
	TerminalType terminalType;
	DateTime? aftDate;

	MessagePullBySessionIdsReq({this.startServerMessageId, this.pageSize = 300, required this.sessionIds,
		required this.terminalType, this.aftDate});

	Map<String, dynamic> toJson() => _$MessagePullBySessionIdsReqToJson(this);
}

@JsonSerializable()
class MessagePullP2pReq extends Req {
	String? serverMessageId;    // 服务端消息id
	int size;                   // 获取个数
	String? fromUserId;         // 拉取某个人发的消息
	String? groupId;            // 拉取某个群的消息
	TerminalType terminalType;  //  拉取终端
	DateTime? aftDate;

	MessagePullP2pReq(this.terminalType, this.size);

	Map<String, dynamic> toJson() => _$MessagePullP2pReqToJson(this);
}

@JsonSerializable()
class MessagePullP2psReq extends Req {
	String? serverMessageId;          // 服务端消息id
	int size;                         // 获取个数
	Set<String>? fromUserIds;         // 拉取某个人发的消息
	Set<String>? groupIds;            // 拉取某个群的消息
	TerminalType terminalType;        // 拉取终端
	DateTime? aftDate;

	MessagePullP2psReq(this.terminalType, this.size);

	Map<String, dynamic> toJson() => _$MessagePullP2psReqToJson(this);
}

@JsonSerializable()
class MessageListItem {
	List<MessageObject> messageObjectList;

	MessageListItem(this.messageObjectList);

	factory MessageListItem.fromJson(Map<String, dynamic> map) =>_$MessageListItemFromJson(map);

	Map<String, dynamic> toJson() => _$MessageListItemToJson(this);
}

enum TerminalType {
	pc,
	android,
	ios,
	pad,
	ipad,
	web,
	hm,
	;
}

enum EnableType {
	enable(1, "有效"),
	disable(2, "无效"),
	;

	final int value;
	final String desc;

	const EnableType(this.value, this.desc);
}

enum SessionStatus {
	enable(1, "可用"),
	disable(2, "不可用"),
	;

	final int value;
	final String desc;

	const SessionStatus(this.value, this.desc);
}

enum SessionType {
	chat(1, "聊天"),
	;

	final int value;
	final String desc;

	const SessionType(this.value, this.desc);
}

enum GroupStatus {
	disable(2, "不可用"),
	enable(1, "可用"),
	dissolution(3, "解散"),
	prohibition(4, "禁言"),
	;

	final int value;
	final String desc;

	const GroupStatus(this.value, this.desc);
}

enum GroupUserStatus {
	disable(2, "不可用"),
	enable(1, "可用"),
	exit(3, "退出"),
	prohibition(4, "禁言"),
	;

	final int value;
	final String desc;

	const GroupUserStatus(this.value, this.desc);
}